import { query,query2 } from "../mysqlQuery.js";
import path, { resolve } from "path";
import fs from "fs";
import Joi from "joi";
import { StringDecoder } from "string_decoder";
import SDTime from "silly-datetime"; //时间格式化处理插件
import { getRandomId } from "../common/index.js";
//总小说表查询
function queryNovelList(){
    query([{
        sql:"select * from app_novel",
        values:[]
    }]).then((data)=>{
        console.log(data[0].rows)
    }).catch((err)=>{
        next(err)
    })
}
//首页推荐表新增
function addRecommend(req,res,next){
    query([{
        sql:"insert into app_recommend (rank_id,novel_id,title,classify_id,create_time,update_time) values (?,?,?,?,?,?)",
        values:[
            getRandomId(8),
            "62009604",
            "书中有位仙",
            "10001",
            SDTime.format(new Date(), "YYYY-MM-DD HH:mm:ss"),
            SDTime.format(new Date(), "YYYY-MM-DD HH:mm:ss")
        ]
    }]).then((data)=>{
        console.log(data[0].rows)
    }).catch((err)=>{
        next(err)
    })
}
//首页推荐表查询
function queryRecommend(){
    query([{
        sql:"select rank_id,novel_id,title,classify_id,hot from app_recommend",
        values:[]
    }]).then((data)=>{
        console.log(data[0].rows)
    }).catch((err)=>{
        next(err)
    })
}
//首页限时免费表新增
function addTimeLimitFree(){
    query([{
        sql:"insert into app_timelimitfree (free_id,novel_id,title,classify_id,now_price,original_price,free_staus,create_time,update_time) values (?,?,?,?,?,?,?,?,?)",
        values:[
            getRandomId(8),
            "62009604",
            "书中有位仙",
            "10001",
            100,
            999,
            1,
            SDTime.format(new Date(), "YYYY-MM-DD HH:mm:ss"),
            SDTime.format(new Date(), "YYYY-MM-DD HH:mm:ss")
        ]
    }]).then((data)=>{
        console.log(data[0].rows)
    }).catch((err)=>{
        next(err)
    })
}
//首页限时免费表查询
function queryTimeLimitFree(){
    query([{
        sql:"select free_id,novel_id,title,classify_id,now_price,original_price,free_staus,create_time,free_longTime from app_timelimitfree",
        values:[]
    }]).then((data)=>{
        console.log(data[0].rows)
    }).catch((err)=>{
        next(err)
    })
}
export {
    addRecommend,
    queryRecommend,
    addTimeLimitFree,
    queryTimeLimitFree,
    queryNovelList
}